package com.naxiang.cn.naxiangvideoplay;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.naxiang.cn.utils.ItemBeen;
import com.naxiang.cn.utils.NaXiangAdapter;

import java.util.List;

/**
 * 作者: 赵航
 * 创建时间: 2018/7/8 15:33
 * 描述:
 */
public class SimpleMediaController extends RelativeLayout {
    private SeekBar        seekBar;
    private ImageView      mViodPicrure;
    private ImageView      mImageStart;
    private ImageView      mMusicClose;
    private ImageView      mFullSecream;
    private LinearLayout   mControl;
    private TextView       mAllTime;
    private TextView       mReadTime;
    private ImageButton    mSliedBar;
    private ListView       mListView;
    private NaXiangAdapter mAdapter;
    private TextView mPeoploNumber;
    private ImageView mShopImage;
    private ImageView mShareScream;
    private TextView mTitleText;
    private ImageView mTitleImage;

    public TextView getTitleText() {
        return mTitleText;
    }

    public ImageView getTitleImage() {
        return mTitleImage;
    }

    public SimpleMediaController(Context context) {
        super(context,null);
        initUI();
    }
    public SimpleMediaController(Context context, AttributeSet attrs) {
        super(context, attrs);
        initUI();
    }

    private void initUI() {
        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.mo_naxiangvideoplay_media_controller_layout, this);
        mViodPicrure = (ImageView) layout.findViewById(R.id.viodpicrure);
        mImageStart= (ImageView) layout.findViewById(R.id.imagestart);
        mMusicClose = (ImageView) layout.findViewById(R.id.musicclose);
        mFullSecream = (ImageView) layout.findViewById(R.id.fullsecream);
        mControl = (LinearLayout) layout.findViewById(R.id.control);
        seekBar = (SeekBar) layout.findViewById(R.id.seekbar);
        mReadTime = (TextView) layout.findViewById(R.id.readtime);
        mSliedBar = (ImageButton) layout.findViewById(R.id.sliedbar);
        mAllTime = (TextView) layout.findViewById(R.id.alltime);
        mListView = (ListView) layout.findViewById(R.id.listview);

        mShopImage = (ImageView) layout.findViewById(R.id.shaoping);
        mShareScream = (ImageView) layout.findViewById(R.id.sharesecream);
        mPeoploNumber = (TextView) layout.findViewById(R.id.livingtext);
        mTitleText = (TextView) layout.findViewById(R.id.titletext);
        mTitleImage = (ImageView) layout.findViewById(R.id.titleimage);

        seekBar.setMax(10000);
    }
    public void seatProgress(int percent){
        seekBar.setProgress(percent);
    }

    public ImageButton getSliedBar() {
        return mSliedBar;
    }

    public TextView getAllTime() {
        return mAllTime;
    }

    public TextView getReadTime() {
        return mReadTime;
    }

    public ImageView getViodPicrure() {
        return mViodPicrure;
    }

    public ImageView getImageStart() {
        return mImageStart;
    }

    public ImageView getMusicClose() {
        return mMusicClose;
    }

    public ImageView getFullSecream() {
        return mFullSecream;
    }

    public LinearLayout getControl() {
        return mControl;
    }

    public SeekBar getSeekBar() {
        return seekBar;
    }

    public ListView getListView() {
        return mListView;
    }

    public TextView getPeoploNumber() {
        return mPeoploNumber;
    }

    public ImageView getShopImage() {
        return mShopImage;
    }

    public ImageView getShareScream() {
        return mShareScream;
    }
    public void setListVisible(boolean b, List<ItemBeen> itemBeens, int listImageWidth, int listImageHeight) {
        LayoutParams params = new LayoutParams(listImageWidth, ViewGroup.LayoutParams.MATCH_PARENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
        mListView.setLayoutParams(params);
        mListView.setCacheColorHint(Color.TRANSPARENT);//让ListView滑动的时候条目背景色不会变成黑色
        mListView.setDivider(null);//去掉条目间的分割线
        mListView.setSelector(new ColorDrawable());//设置默认状态选择器为全透明，不传颜色就是没颜色（也就是条目被点击时，背景没颜色）
        if (b){
            mListView.setVisibility(VISIBLE);
        }else {
            mListView.setVisibility(INVISIBLE);
        }
        if (mAdapter==null) {
            mAdapter = new NaXiangAdapter(itemBeens,listImageWidth,listImageHeight);
            mListView.setAdapter(mAdapter);
        }else {
            mAdapter.notifyDataSetChanged();
        }
    }
}